package czk.concrent.review.synControl;

import java.util.concurrent.locks.LockSupport;

/**
 * @Author:ChenZhangKun
 * @Date: 2020/7/22 23:28
 */
public class LockSupportSynControl {
    static Thread t1;
    static Thread t2;
    static Thread t3;

    public static void main(String[] args) {
        LockSupportTest lockSupportTest=new LockSupportTest(5);
        t1=new Thread(()->{
            lockSupportTest.print("A",t2);
        });
        t2=new Thread(()->{
            lockSupportTest.print("B",t3);
        });
        t3=new Thread(()->{
            lockSupportTest.print("C",t1);
        });
        // 唤醒
        t1.start();
        t2.start();
        t3.start();
        LockSupport.unpark(t2);
    }
}
class LockSupportTest{
    private int loopNum;

    public LockSupportTest(int loopNum) {
        this.loopNum = loopNum;
    }
    public void print(String content,Thread next){
        for (int i = 0; i < loopNum; i++) {
            LockSupport.park();
            System.out.print(content);
            LockSupport.unpark(next);
        }
    }
}
